<?php
require_once ("../src/db/connectdatabase.php");

function getQuestionByID($idquestion) {
	$con = new ConnectDB();
	$tbl = "loan_question_cong_tac_vien";
	$fn = array('idques', 'question', 'answerq');
	$condetion = array('idques' => $idquestion);
	return $con -> getvalue($tbl, $fn, $condetion);
}

if(isset($_GET['id'])) {
	$idquestion = $_GET['id'];
	$question = getQuestionByID($idquestion);
	if(count($question) == 1) {
	?>
<h3>Cập Nhật Câu Hỏi Chương Trình Cộng Tác Viên</h3>
<div style="color: red;">
<?php
	if(isset($_GET['mess'])) {
		echo($_GET['mess']);
	}
?>
</div>
<div style="width: 850px;">
	<form action="../src/control/AdminQuestionCongTacVien.php" method="post" onSubmit="return checkvaluequestion();">
        <table>
            <tr>
                <th valign="top" width="100px;">Câu Hỏi</th>
                <td>
                    <input type="hidden" value="<?php echo($question[0][0]) ?>" name="cauhoiid" id="cauhoiid" />
                    <input id="textfieldquestion" name="textfieldquestion" type="text" style="width: 750px; height:30px; padding-left:5px; padding-right:5px;" value="<?php echo($question[0][1]) ?>" /><br><font color="red"><span id="err_cauhoi"></span></font>
                </td>
            </tr>
            <tr>
            	<th valign="top">Trả Lời</th>
                <td>
                	<textarea id="textfieldanswerquestion" name="textfieldanswerquestion" rows="20" cols="200" style="width: 750px; max-width:750px; min-width:750px;" class="tinymce"><?php echo($question[0][2]) ?></textarea><br><font color="red"><span id="err_cautraloi"></span></font>
                </td>
            </tr>
            <tr>
            	<th colspan="2"><input type="hidden" name="acc" value="edit" /><input type="submit" value="Cập Nhật" style="border-radius: 5px; padding:5px; width:150px; background:#03F; color:#FFF; font-weight:bold;" /></th>
            </tr>
        </table>
    </form>
</div>
<script>
function checkvaluequestion() {
	var cauhoi = $.trim($('#textfieldquestion').val());
	var answer = $.trim($('#textfieldanswerquestion').val());
	
	if(cauhoi.length == 0) {
		$('#err_cauhoi').html("Vui lòng nhập thông tin câu hỏi!");
		$('#textfieldquestion').focus();
		return false;
	} else {
		$('#err_cauhoi').html("");
	}
	
	if(answer.length == 0) {
		$('#err_cautraloi').html("Vui lòng nhập thông tin câu trả lời!");
		$('#textfieldanswerquestion').focus();
		return false;
	} else {
		$('#err_cautraloi').html("");
	}
}
</script>
<?php
	}
}
?>